package com.chat.websocket.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.chat.constant.tab.MessageConstant;
import com.chat.dao.LeaveMsgDao;
import com.chat.entity.TdChatLeaveMsg;

/**
 * 离线信息业务
 * 
 * @author lwh
 *
 */
@Service
public class LeaveMsgService {

	@Autowired
	private LeaveMsgDao leaveMsgDao;

	/**
	 * 把离线信息存储入库
	 * 
	 * @param leavetype
	 * @param bodytype
	 * @param body
	 * @param fromuser
	 * @param tousers
	 */
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void saveLeaveMsg(Integer leavetype, Integer bodytype, String body, String fromuser, String tousers,
			String createTime) {
		TdChatLeaveMsg lmsg = new TdChatLeaveMsg();
		lmsg.setLeavetype(leavetype);
		lmsg.setBodytype(bodytype);
		lmsg.setBody(body);
		lmsg.setFromuser(fromuser);
		lmsg.setTousers(tousers);
		lmsg.setCreatetime(createTime);
		lmsg.setIspushed(MessageConstant.Ispushed_No);
		// 添加一条离线信息
		leaveMsgDao.insertOneLeaveMsg(lmsg);
	}

}
